package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyDiscuss;
import cn.wolfcode.trip.base.domain.TravelDiscuss;
import cn.wolfcode.trip.base.mapper.StrategyDiscussMapper;
import cn.wolfcode.trip.base.mapper.TravelDiscussMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategyDiscussService;
import cn.wolfcode.trip.base.service.ITravelDiscussService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TravelDiscussServiceImpl implements ITravelDiscussService {
    @Autowired
    private TravelDiscussMapper mapper;
    
    @Override
    public PageInfo<TravelDiscuss> selectList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<TravelDiscuss> list = mapper.selectForList(qo);
        return new PageInfo<>(list);
    }


    @Override
    public void saveOrUpdate(TravelDiscuss travelDiscuss) {

        Date date = new Date();

        if (travelDiscuss.getId() == null) {
            travelDiscuss.setCreateTime(date);
            mapper.insert(travelDiscuss);

        } else {
            mapper.updateByPrimaryKey(travelDiscuss);
        }
    }

    @Override
    public TravelDiscuss selectById(Long id) {
        return mapper.selectByPrimaryKey(id);

    }

    @Override
    public int selectCount(Long commentId) {
        return mapper.selectCount(commentId);
    }
}
